import { readFileSync } from "fs";

/**
 * 该方法强依赖与fs模块
 * @param filePath
 * @returns
 */
export function readAndProcessFile(filePath: string): string {
  const content = readFileSync(filePath, { encoding: "utf-8" });

  return content + " test unit";
}

export interface FileReader {
  read(filePath: string): string;
}

/**
 * 使用依赖注入，修改后不在有强依赖
 * @param filePath
 * @returns
 */
export function DIReadAndProcessFile(
  filePath: string,
  fileReader: FileReader
): string {
  const content = fileReader.read(filePath);

  return content + " test unit";
}
